package com.example.yiwei.crm.json;

import android.util.Log;

import com.example.yiwei.crm.entity.ClueMeesageEntity;
import com.example.yiwei.crm.util.NetWorkUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/12.
 */

public class clueJson {
    public static List<ClueMeesageEntity> querySimpleClueMessage(String url, String para){
        List<ClueMeesageEntity> clueList;
        String result= NetWorkUtils.getCount(url,para);
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("boolen");
            if(boolen.equals("success")){
                clueList= new ArrayList<>();
                JSONArray array=object.getJSONArray("list");
                for(int i=0;i<array.length();i++){
                    ClueMeesageEntity clue=new ClueMeesageEntity();
                    JSONObject json = array.getJSONObject(i);
                    clue.setTag(boolen);
                    //线索id
                    if(json.has("XAA01")){
                        clue.setClue_id(json.getInt("XAA01"));
                    }
                    //负责人ID
                    if(json.has("XAA02")){
                        clue.setClue_manager(json.getInt("XAA02"));
                    }
                    //负责人姓名
                    if (json.has("UAB03")){
                        clue.setClue_manager_name(json.getString("UAB03"));
                    }
                    //线索名
                    if (json.has("XAA03")){
                        clue.setClue_name(json.getString("XAA03"));
                    }
                    //性别
                    if (json.has("XAA04")){
                        clue.setClue_gender(json.getInt("XAA04"));
                    }
                    //年龄
                    if (json.has("XAA05")){
                        clue.setClue_age(json.getInt("XAA05"));
                    }
                    //疾病种类id
                    if (json.has("AKB01")){
                        clue.setClue_disease_category_id(json.getInt("AKB01"));
                    }
                    //疾病种类
                    if (json.has("AKB03")){
                        clue.setClue_disease_category(json.getString("AKB03"));
                    }
                    //联系人
                    if (json.has("XAA06")){
                        clue.setClue_contact(json.getString("XAA06"));
                    }
                    //电话
                    if (json.has("XAA07")){
                        clue.setClue_phone(json.getString("XAA07"));
                    }
                    //手机
                    if (json.has("XAA08")){
                        clue.setClue_mobile_phone(json.getString("XAA08"));
                    }
                    //电子邮箱
                    if (json.has("XAA09")){
                        clue.setClue_mail(json.getString("XAA09"));
                    }
                    //微博
                    if (json.has("XAA10")){
                        clue.setClue_weibo(json.getString("XAA10"));
                    }
                    // 邮编
                    if (json.has("XAA11")){
                        clue.setClue_Zip_Code(json.getString("XAA11"));
                    }
                    //地址
                    if (json.has("XAA12")){
                        clue.setClue_address(json.getString("XAA12"));
                    }
                    //渠道分类id
                    if (json.has("AKC01")) {
                        clue.setClue_channel_classification_id(json.getInt("AKC01"));
                    }
                    //渠道分类
                    if (json.has("AKC03")) {
                        clue.setClue_channel_classification(json.getString("AKC03"));
                    }
                    //渠道来源id
                    if (json.has("AKD01")) {
                        clue.setClue_channel_source_id(json.getInt("AKD01"));
                    }
                    //渠道来源
                    if (json.has("AKD03")) {
                        clue.setClue_channel_source(json.getString("AKD03"));
                    }
                    //所属部门
                    if (json.has("XAA13")) {
                        clue.setClue_department_id(json.getInt("XAA13"));
                    }
                    //下次联系时间
                    if (json.has("XAA14")) {
                        clue.setClue_next_time(json.getString("XAA14"));
                    }
                    //下次联系内容
                    if (json.has("XAA15")) {
                        clue.setClue_next_content(json.getString("XAA15"));
                    }
                    //附加备注内容
                    if (json.has("XAA16")) {
                        clue.setClue_additional(json.getString("XAA16"));
                    }
                    //跟进状态
                    if (json.has("XAA17")) {
                        clue.setClue_follow_status(json.getInt("XAA17"));
                    }
                    //是否关注
                    if (json.has("XAA18")) {
                        clue.setClue_is_attention(json.getInt("XAA18"));
                    }
                    //排序
                    if (json.has("SRT01")) {
                        clue.setClue_sort(json.getInt("SRT01"));
                    }
                    //附加备注内容
                    if (json.has("REK01")){
                        clue.setClue_additional(json.getString("REK01"));
                    }
                    //创建时间
                    if (json.has("CTS01")){
                        clue.setClue_create_time(json.getString("CTS01"));
                    }
                    //更新时间
                    if (json.has("UTS01")){
                        clue.setClue_update_time(json.getString("UTS01"));
                    }
                    //当前创建用户id
                    if (json.has("CID01")){
                        clue.setClue_current_create_id(json.getInt("CID01"));
                    }
                    //当前更新用户id
                    if (json.has("UID01")){
                        clue.setClue_current_update_id(json.getInt("UID01"));
                    }
                    clueList.add(clue);
                }

                return clueList;
            }else{
                Log.d("","查询失败");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
    public static ClueMeesageEntity queryDetailedClueMessage(String durl, String dpara) {
        String result = NetWorkUtils.getCount(durl, dpara);
        try {
            JSONObject object = new JSONObject(result);
            String boolen = object.getString("boolen");
            if (boolen.equals("success")) {
                JSONArray array = object.getJSONArray("list");
                for (int i = 0; i < array.length(); i++) {
                    ClueMeesageEntity clue = new ClueMeesageEntity();
                    JSONObject json = array.getJSONObject(i);
                    clue.setTag(boolen);
                    //线索id
                    if (json.has("XAA01")) {
                        clue.setClue_id(json.getInt("XAA01"));
                    }
                    //负责人ID
                    if (json.has("XAA02")) {
                        clue.setClue_manager(json.getInt("XAA02"));
                    }
                    //负责人姓名
                    if (json.has("UAB03")){
                        clue.setClue_manager_name(json.getString("UAB03"));
                    }
                    //线索名
                    if (json.has("XAA03")) {
                        clue.setClue_name(json.getString("XAA03"));
                    }
                    //性别
                    if (json.has("XAA04")) {
                        clue.setClue_gender(json.getInt("XAA04"));
                    }
                    //年龄
                    if (json.has("XAA05")) {
                        clue.setClue_age(json.getInt("XAA05"));
                    }
                    //疾病种类id
                    if (json.has("AKB01")) {
                        clue.setClue_disease_category_id(json.getInt("AKB01"));
                    }
                    //疾病种类
                    if (json.has("AKB03")) {
                        clue.setClue_disease_category(json.getString("AKB03"));
                    }
                    //联系人
                    if (json.has("XAA06")) {
                        clue.setClue_contact(json.getString("XAA06"));
                    }
                    //电话
                    if (json.has("XAA07")) {
                        clue.setClue_phone(json.getString("XAA07"));
                    }
                    //手机
                    if (json.has("XAA08")) {
                        clue.setClue_mobile_phone(json.getString("XAA08"));
                    }
                    //电子邮箱
                    if (json.has("XAA09")) {
                        clue.setClue_mail(json.getString("XAA09"));
                    }
                    //微博
                    if (json.has("XAA10")) {
                        clue.setClue_weibo(json.getString("XAA10"));
                    }
                    // 邮编
                    if (json.has("XAA11")) {
                        clue.setClue_Zip_Code(json.getString("XAA11"));
                    }
                    //地址
                    if (json.has("XAA12")) {
                        clue.setClue_address(json.getString("XAA12"));
                    }
                    //渠道分类id
                    if (json.has("AKC01")) {
                        clue.setClue_channel_classification_id(json.getInt("AKC01"));
                    }
                    //渠道分类
                    if (json.has("AKC03")) {
                        clue.setClue_channel_classification(json.getString("AKC03"));
                    }
                    //渠道来源id
                    if (json.has("AKD01")) {
                        clue.setClue_channel_source_id(json.getInt("AKD01"));
                    }
                    //渠道来源
                    if (json.has("AKD03")) {
                        clue.setClue_channel_source(json.getString("AKD03"));
                    }
                    //所属部门
                    if (json.has("XAA13")) {
                        clue.setClue_department_id(json.getInt("XAA13"));
                    }
                    //下次联系时间
                    if (json.has("XAA14")) {
                        clue.setClue_next_time(json.getString("XAA14"));
                    }
                    //下次联系内容
                    if (json.has("XAA15")) {
                        clue.setClue_next_content(json.getString("XAA15"));
                    }
                    //附加备注内容
                    if (json.has("XAA16")) {
                        clue.setClue_additional(json.getString("XAA16"));
                    }
                    //跟进状态
                    if (json.has("XAA17")) {
                        clue.setClue_follow_status(json.getInt("XAA17"));
                    }
                    //是否关注
                    if (json.has("XAA18")) {
                        clue.setClue_is_attention(json.getInt("XAA18"));
                    }
                    //排序
                    if (json.has("SRT01")) {
                        clue.setClue_sort(json.getInt("SRT01"));
                    }
                    //附加备注内容
                    if (json.has("REK01")) {
                        clue.setClue_additional(json.getString("REK01"));
                    }
                    //创建时间
                    if (json.has("CTS01")) {
                        clue.setClue_create_time(json.getString("CTS01"));
                    }
                    //更新时间
                    if (json.has("UTS01")) {
                        clue.setClue_update_time(json.getString("UTS01"));
                    }
                    //当前创建用户id
                    if (json.has("CID01")) {
                        clue.setClue_current_create_id(json.getInt("CID01"));
                    }
                    //当前更新用户id
                    if (json.has("UID01")) {
                        clue.setClue_current_update_id(json.getInt("UID01"));
                    }
                    return clue;
                }
            } else {
                Log.d("", "查询失败");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
         return null;
    }
}
